﻿$ErrorState = 2
$ErrorMessage = ""
$Trace = ""
$Value = ""
$Error.Clear()

$VMHostName = "%HOSTNAME%"

$VMHost = ""

           
try {
            
	Add-PSSnapin Microsoft.SystemCenter.VirtualMachineManager

    $Trace += 'Connecting to VMM Server...  \n'

	$VMMServer = Get-VMMServer -ComputerName localhost

	$vm_host = Get-VMHost -ComputerName $VMHostName

	Refresh-VMHost -VMHost $vm_host
	$ErrorState = 0
}
catch {
    $ErrorState = 2
    $ErrorMessage = $error[0].Exception.ToString()
}
Finally {
    $Trace += 'ErrorState:  ' + $ErrorState + ' \n'
    $Trace += 'ErrorMessage: ' + $ErrorMessage + ' \n'
   
}
            
$Results = @($ErrorState, $ErrorMessage, $Trace, $VMHost) 
Return $Results
